package com.gopay.commons.validator.check;

import java.util.Iterator;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.gopay.commons.validator.form.Field;
import com.gopay.commons.validator.form.Validator;

/**
 * 为空校验
 * 
 * @DefaultRequiredValidator.java
 * @author yaobo
 * @2012-12-26 上午09:55:38 www.gopay.com.cn Inc.All rights reserved.
 */
public class DefaultRequiredValidator extends DefaultValidator {
    @Override
    protected boolean validator(Field field) {
        List<Validator> validators = field.getValidators();
        Validator validator = null;

        for (Iterator<Validator> it = validators.iterator(); it.hasNext();) {
            validator = (Validator) it.next();
            if (validator.isRequried()) {
                String value = (String) field.getValue();
                if (StringUtils.isBlank(value)) {
                    return false;
                }
                break;
            }
        }

        return true;
    }
}
